<?php

namespace App\Http\Requests;

/**
 * 自动回复表单验证规则
 * @package App\Http\Requests
 */
class AdminWxAutoreplyPost extends AdminBaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' => 'required',
            'keywords' => 'required',
            'is_open' => 'in:0,1',
            'start_time' => 'nullable|date|before:end_time',
            'end_time' => 'nullable|date|after:start_time',
            'msg_type' => 'required|in:text,news,image,video,voice,music',
            'order_num' => 'integer|min:0',
            'content' => 'required_if:msg_type,text',
            'material.material_id' => 'required_if:msg_type,news,image,video,voice',
            'material.title' => 'required_if:msg_type,music',
            'material.description' => 'required_if:msg_type,music',
            'material.music_url' => 'required_if:msg_type,music',
            'material.thumb_view_url' => 'required_if:msg_type,music',
        ];
    }

    /**
     * 定义错误信息
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '请给自动回复命名',
            'keywords.required' => '请输入关键字',
            'is_open.in' => '请选择是否开启',
            'start_time.date_format' => '请输入正确的时间格式',
            'start_time.before' => '开始时间必须早于结束时间',
            'end_time.date_format' => '请输入正确的时间格式',
            'end_time.after' => '开始时间必须早于结束时间',
            'msg_type.required' => '请选择正确的回复类型',
            'msg_type.in' => '请选择正确的回复类型',
            'order_num.min' => '排序数值必须大于或等于0',
            'content.required_if' => '请填写回复内容',
            'material.material_id.required_if' => '请选择有效的素材',
            'material.title.required_if' => '请输入标题',
            'material.description.required_if' => '请输入描述',
            'material.thumb_view_url.required_if' => '请上传封面图',
            'material.music_url.required_if' => '请输入音乐链接',
        ];
    }
}
